load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "poison_proto",
    srcs = [
        "error.proto",
        "policy.proto",
    ],
    strip_import_prefix = "/pkg",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/roachpb:roachpb_proto",
        "//pkg/util/hlc:hlc_proto",
        "@com_github_gogo_protobuf//gogoproto:gogo_proto",
    ],
)

go_proto_library(
    name = "poison_go_proto",
    compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
    importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison",
    proto = ":poison_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/roachpb",
        "//pkg/util/hlc",
        "@com_github_gogo_protobuf//gogoproto",
    ],
)

go_library(
    name = "poison",
    srcs = ["error.go"],
    embed = [":poison_go_proto"],
    importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/roachpb",
        "//pkg/util/hlc",
        "@com_github_cockroachdb_errors//:errors",
    ],
)

go_test(
    name = "poison_test",
    srcs = ["error_test.go"],
    data = glob(["testdata/**"]),
    deps = [
        ":poison",
        "//pkg/keys",
        "//pkg/roachpb",
        "//pkg/testutils/echotest",
        "//pkg/util/hlc",
        "//pkg/util/leaktest",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_stretchr_testify//require",
    ],
)
